export function getLocation() {
	uni.authorize({
		scope: 'scope.userLocation',
		success(res) {
			console.log(res);
			//实例化
			// let qqMapSdk = new QQMapWX({
			//     key: '你的key值'
			// })
			// uni.getLocation({
			//     type: 'wgs84',
			//     success(result:any){
			//         qqMapSdk.reverseGeocoder({
			//             location: {
			//                 latitude: result.latitude,
			//                 longitude: result.longitude
			//             },
			//             success(res:any) {
			//                 console.log('定位res',res)
			//                 mapBack(res.result.ad_info.province, res.result.ad_info.city)
			//             },
			//             fail(err:any) {
			//                 uni.showToast({
			//                     icon: 'error',
			//                     title: '逆地址解析失败',
			//                     duration: 2000
			//                 })
			//                 console.log('逆地址解析失败',err);
			//             }
			//         })
			//     }
			// })
		},
		fail() {
			uni.showToast({
				icon: 'error',
				title: '注意：需要授权获取定位，否则部分功能将无法使用',
				duration: 2000,
			});
		},
	});
}

/**
 * 转换为后端的定位编码
 * @province 需要转换编码的省份
 * @city 需要转换编码的城市
 * */
export function mapBack(province: string, city: string) {
	const localLocation = JSON.parse(uni.getStorageSync('address'));
	localLocation.map((item: { name: any; address: any[]; id: any }) => {
		if (item.name == province.substr(0, province.length - 1)) {
			// that.locationInfo.province_code = ''
			// that.locationInfo.city_code = item.id
		} else {
			item.address.map((items) => {
				if (items.name == city.substr(0, city.length - 1)) {
					// that.locationInfo.province_code = item.id
					// that.locationInfo.city_code = items.id
				}
			});
		}
	});
	// 本地保存定位
	// uni.setStorageSync('location', that.locationInfo)
	// 更新全局定位数据
	// uni.setStorageSync('located', true)
}
